
          var userAry = [];
          var username = document.querySelector(".username input");
          username.addEventListener("blur", checkUsername);
          // 功能1:验证用户名是否合法
          function checkUsername() {
              var reg = /^\w{6}$/;
              var v = username.value;
              if(!reg.test(v)) {
                username.nextElementSibling.innerHTML = "用户名必须是6位";
                username.nextElementSibling.style.color = "red";
                  return false;
              }else {
                username.nextElementSibling.innerHTML = "";
                  return true;
              }
          }
 
          var phone= document.querySelector(".phone input");
          phone.addEventListener("blur", checkPhone);
          // 功能2: 验证手机号:
          function checkPhone() {
              var reg = /^13[0-9](\d){8}|15[0-9](\d){8}$/;
              var v = phone.value;
              if(!reg.test(v)) {
                phone.nextElementSibling.innerHTML = "手机号必须是13或者15开头";
                phone.nextElementSibling.style.color = "red";
                  return false;
              }else {
                phone.nextElementSibling.innerHTML = "";
                 return true;
              }
 
          }
 
          // 功能5: 验证验证码
          var code_num = document.querySelector(".code input");
          code_num.addEventListener("blur", checkCode)
          function checkCode() {
              var reg = /^\d{6}$/;
              var v = code_num.value;
              if(!reg.test(v)) {
                code_num.nextElementSibling.nextElementSibling.innerHTML = "请输入6位数字";
                code_num.nextElementSibling.nextElementSibling.style.color = "red";
                  return false;
              }else {
                code_num.nextElementSibling.nextElementSibling.innerHTML = "";
                  return true;
              }
          }
 
          // 功能4: 点击发送验证码
          var code = document.querySelector(".code a");
          var i = 5;
          var flg = true;
          var timeID;
          code.addEventListener("click", function(){
                if(flg) {
                   code.innerHTML= "05秒后重新获取";
                   flg = false;
                   timeID = setInterval(function(){
                      i--;
                      if(i == 0) {
                         code.innerHTML = `重新获取`;
                         flg = true;
                         i = 5;
                         code_num.disabled = false;
                         clearInterval(timeID);
                      }else {
                         code.innerHTML = `0${i}秒后重新获取`;
                      }
                      code.style.color = "#27BA9B";
                   }, 1000)
                }
          });
 
 
          // 功能6: 验证密码
          var password = document.querySelector(".password input");
          password.addEventListener("blur", checkpwd);
          function checkpwd() {
             var reg = /^\w{6,20}$/;
             var v = password.value;
             if(!reg.test(v)) {
                password.nextElementSibling.innerHTML = "请输入6-20位密码";
                password.nextElementSibling.style.color = "red";
                return false;
             }else {
                password.nextElementSibling.innerHTML = "";
                return true;
             }
          }
 
 
          // 功能7: 确认密码
          var confirm = document.querySelector(".confirm input");
          confirm.addEventListener("blur", checkConf);
          function checkConf() {
              var  v = confirm.value;
              if(v == password.value) {
                confirm.nextElementSibling.innerHTML = "";
                  return true;
              }else {
                confirm.nextElementSibling.innerHTML = "两次密码输入不一致";
                confirm.value = "";
                confirm.nextElementSibling.style.color = "red";
                  return false;
              }
          }
          
          // 功能8: 点击下一步
          var btn= document.querySelector(".btn");
          var aggred = document.querySelector(".aggred input");
          btn.addEventListener("click", function(e){
              e.preventDefault();
              if(!aggred.checked) {
                  alert('请选择同意');
                  return;
              }
              // 验证是否全部通过
              if(checkUsername() && checkPhone() && checkCode() && checkpwd() && checkConf()) {
                   // 注册信息 userAry
                   var user = {
                       uname:username.value,
                       phone:phone.value,
                       password:password.value
                   }
 
                   // 检测当前账户是否存在,如果存在,则提示存在,重新注册,否则提示注册成功
                   var res = JSON.parse(localStorage.getItem("userInfo")) || [];
 
                   var flg =  res.some(function(item){
                       return  item.phone == user.phone;
                   });
 
                   if(flg) {
                       alert("当前手机号已被注册请重新填写信息");
                       document.querySelector("form").reset();
                   }else {
                       userAry.push(user);
                       localStorage.setItem("userInfo", JSON.stringify(userAry));
                       alert("注册成功,页面跳转中..");
                       document.querySelector("form").reset();
                       location.href = "./login.html";
                   }
                   
              }else {
                  return;
              }
          });
